package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

public class NotificationActivity extends AppCompatActivity {
   private NotificationManager manager;
    private Notification notification;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification);
        manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
            NotificationChannel channel= new NotificationChannel("leo","测试通知",NotificationManager.IMPORTANCE_HIGH);
                 manager.createNotificationChannel(channel);
        }
        Intent intent=  new Intent(this,Notifition2Activity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,0);
         notification= new NotificationCompat.Builder(this,"leo")
                .setContentTitle("官方通知")
                .setContentText("这是一个通知")
                .setSubText("通知你要学习了！")
//                .setLargeIcon(R.drawable.ic_launcher_foreground)
                 .setSmallIcon(R.drawable.ic_launcher_foreground)
                 .setColor(Color.parseColor("#FF0000"))
                 .setContentIntent(pendingIntent)
                 .setAutoCancel(true)
                .build();

    }


    public void makeNotification(View view) {
        manager.notify(1,notification);
    }

    public void cancelNotification(View view) {
        manager.cancel(1);
    }
}